package com.group11.base.service.impl;

import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.group11.base.entity.Region;
import com.group11.base.mapper.RegionMapper;
import com.group11.base.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements RegionService {
    @Autowired
    private RegionMapper regionMapper;

    @Override
    public List<Region> list(Region region) {
        QueryWrapper<Region> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq(region.getId() != null && region.getId() != 0, "id", region.getId())
                .eq(region.getPid() != null && region.getPid() != 0, "pid", region.getPid())
                .like(StringUtils.hasText(region.getName()), "name", region.getName())
                .eq(StringUtils.hasText(region.getLetter()), "letter", region.getLetter())
                .eq(region.getSort() != null && region.getSort() != 0, "sort", region.getSort());
        return regionMapper.selectList(queryWrapper);
    }
}
